Deployments
:它的角色比較像是幫你管理Pod,在yaml中指定副本數(replicas)後會維持Pod剛好等於指定數量,也就是說可以用來達到自我修復
的功能。除此之外它還有滾動更新
的功能(之後再提),可以更換Pod裡容器的image版本。
Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-demo
labels:
app: ubuntu
spec:
replicas: 2
selector:
matchLabels:
app: ubuntu
template:
metadata:
labels:
app: ubuntu
spec:
containers:
- name: ubuntu
image: ubuntu:20.04
args: [bash, -c, 'for ((i = 0; ; i++)); do echo "$i: $(date)"; sleep 100; done']
部屬Deployment
root@master:/# kubectl apply -f deployment.yaml
deployment.apps/deployment-demo created
查看Deployment
root@master:/# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
deployment-demo 2/2 2 2 20s
查看pod
root@master:/# kubectl get pod
NAME READY STATUS RESTARTS AGE
deployment-demo-68d5b9f46-4d4z9 1/1 Running 0 4s
deployment-demo-68d5b9f46-zthrv 1/1 Running 0 4s
先刪除deployment-demo-68d5b9f46-4d4z9
,再查看pod
root@master:/# kubectl delete pod deployment-demo-68d5b9f46-4d4z9
pod "deployment-demo-68d5b9f46-4d4z9" deleted
root@master:/# kubectl get pod
NAME READY STATUS RESTARTS AGE
deployment-demo-68d5b9f46-fs2lf 1/1 Running 0 78s
deployment-demo-68d5b9f46-zthrv 1/1 Running 0 104m